# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import json
from pymongo import MongoClient
import pymongo
from decimal import Decimal
city=sys.argv[1]
db_name=sys.argv[2]
client=MongoClient("101.200.122.53",3719)
db=client['admin']
db.authenticate('zhuge', '7UgfAWbUtTKeMVGrSLwsHjB9xGjumnck')
db=client[db_name]
borough_price_file="%s/cityarea2" % city
def default(obj):
    if isinstance(obj, Decimal):
        return str(obj)
    raise TypeError
newitem={}
print 'haha'
name_list = {}
with open(borough_price_file, 'w') as f:
    print 'count=',db['cityarea2'].find().count()
    cnt=0
    for item in db['cityarea2'].find(no_cursor_timeout=True):
        try:
            f.write('\t'.join([str(item['location']['coordinates'][0]), str(item['location']['coordinates'][1]),item['name'],'\n']))
        except Exception as e:
            print e
    f.close()
